<?
	require_once('init.php');
	require_once('dataModel.php');

	$_SESSION["MenuID"]='';

    /*获得所有客服数量*/
	$sql = "select COUNT(*) as RowNum from empInfo where shopRoomID=".$_SESSION["UID"]."";
	$db = MySQL::getInstance('','r-w'); 
	$result = $db->fetch($db->query($sql));
    $rs_count=$result["RowNum"];
    
    /*获得当前的页码数*/
	if(!$_GET['pgno'])
	{
		$PageNo = 1;
	}
	else
	{
		$PageNo = $_GET['pgno'];
	}

	$total_showpages = 10;  /*需显示的总页*/
	$num_perpage = 10;    /*每页所显示的数量*/

	$from = ($PageNo-1)*$num_perpage;	/*每页所显示的起始数量*/
	$total_pages = ceil($rs_count / $num_perpage); /*总页数*/
	
	if($total_pages>=$PageNo+$total_showpages)
	{
		$start = $PageNo;
		$stop = $PageNo+$total_showpages-1;
	}
	elseif($total_pages < $PageNo+$total_showpages)
	{
		if($total_pages>$total_showpages)
		{
			$start = $total_pages-$total_showpages+1;
			$stop = $total_pages;		
		}
		else
		{
			$start = 1;
			$stop = $total_pages;
		}
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=<?='utf-8';?>" />
	<title><?=$AllPageTitle;?></title>
	<link href="css/CenterMenu.css" rel="stylesheet" type="text/css" />
	<link href="css/Buttonstyle.css" rel="stylesheet" type="text/css" />
	
	
	<!--注意，不要改变以下三行格式 -->
	<script src="Scripts/jquery.min.js" type="text/javascript"></script>
	<script src="Scripts/jquery.ui.draggable.js" type="text/javascript"></script>
	<script src="Scripts/jquery.hiAlerts-min.js" type="text/javascript"></script>
	
	<script language="javascript">
		function addempName()
		{
			var strSQL = "";                      
			strSQL+= "&Type=empNameNum";
			
			$.post("varifyData.php",strSQL,function(msg)
			{
//			    alert (msg);
			   	if (msg=='1')
			   	{	
					self.location="empaddnew.php?Type=0'";
					return false;
			   	}
			   	else if (msg=='2')
			   	{
					parent.hiAlert("客服人员数量已达到最大值，不允许继续增加!", '系统提示');
					$("#empName").focus();
					return false;
			   	}
			})
		}
		
   		function DeleteEmp(EID)
   		{
			var strSQL = "";                      
			strSQL+= "EID="+EID;
			strSQL+= "&Type=DeleteEmp";

			parent.hiConfirm('确定删除当前客服吗?', '系统提示', function(r) 
			{       
				if (r) 
				{
					$.post("varifyData.php",strSQL,function(msg)
					{
					   	if (msg=='1')
					   	{	
							parent.hiAlert("数据删除完毕!", '系统提示');
							setTimeout('location.reload();parent.$("#popup_ok").click();',3000); //主动关闭提示，否则遮住了
							return false;
					   	}
					})
				}	
			})	
		}    
	</script>
</head>

<body>
	<div id="MenuRighttitle" ><div style="padding-left:245px;padding-top:5px;"><b><?="客服人员管理";?></b></div></div>
	
	<div class="inner-container">
		<div class="empinfo_a01">	
			<div class="empinfo_a02">
				<?
					$strSQL= "select U.id,U.userName,U.effectNum,";  
					$strSQL.="       R.shopRoomID,R.roomName,R.effectDate,";
					$strSQL.="       (CASE R.useType WHEN '1' THEN '付费用户' ELSE '试用用户' END) AS useType, ";  
					$strSQL.="       (CASE R.serverType WHEN '1' THEN '独立服务类型' ELSE '公共服务类型' END) AS serverType ";  
					$strSQL.="from userInfo U LEFT JOIN roomBaseInfo R ON R.userID=U.id ";  
					$strSQL.="where U.userName='".$_SESSION["userName"]."' limit 0,1 "; 
				
					$db = MySQL::getInstance('','r-w'); 
					$DBR=$db->query($strSQL); 
				  	$result=$db->fetch($DBR);
				?>
				
				<div class="empinfo_b01"><b><?="使用类型:".$result["useType"];?><b></div>
				<div class="empinfo_b01"><b><?="有效日期:".date("Y-m-d",strtotime($result["effectDate"]));?><b></div>
				<div class="empinfo_b01"><b><?="客服数量:".$result["effectNum"]."人";?><b></div>
				<button class=btnblue_mouseout onmouseover="this.className='btnblue_mouseover'" onmouseout="this.className='btnblue_mouseout'" onmousedown="this.className='btnblue_mousedown'"  onmouseup="this.className='btnblue_mouseup'" style="height:25px;width:50px;float:right;margin-right:20px;" onclick="addempName()" ><?="新  增";?></button>
            </div> 

			<div class="empinfo_a03">
				<!--显示列表头-->
				<div class="empinfo_a04">
					<div class="empinfo_a05"></div>
					<div class="empinfo_a06" style="color:blue"><b>序号</b></div>
					<div class="empinfo_a07" style="color:blue"><b>客服账号</b></div>
					<div class="empinfo_a08" style="color:blue"><b>登录密码</b></div>
					<div class="empinfo_a09" style="color:blue"><b>即时通讯号码</b></div>
					<div class="empinfo_a10" style="color:blue"><b>客服类型</b></div>
					<div class="empinfo_a11" style="color:blue"><b>操作</b></div>
		    	</div>

				<!--显示具体内容-->
				<?
				$qry  = "select id,empName,empPwd,concat((CASE imType WHEN '0' THEN '旺旺：' ELSE ' QQ：' END),imNumber) AS imNumber,(CASE empType WHEN '1000' THEN '掌门人' ELSE '一般客服' END) AS empType ";
				$qry .= "from empInfo ";
				$qry .= "where shopRoomID=".$_SESSION["UID"]." ";
				$qry .= "order by ID limit ".$from.",".$num_perpage."";

				$db = MySQL::getInstance('','r-w'); 
				$DBR=$db->query($qry); 

				$bkcolor="#F5F5F5";
		    	$i_web = 1;
		      	while($objEmp=$db->fetch($DBR))
		    	{
		      	    if ($bkcolor=="white")
		      	    {$bkcolor="#F5F5F5";}
		      	    else
		      	    {$bkcolor="white";}
		      	    
		      	?>
					<div class="empinfo_a04" style="background-color:<?=$bkcolor;?>">
						<div class="empinfo_a05"></div>
						
						<? $ShowNum=$num_perpage*($PageNo-1)+$i_web; ?>

						<div class="empinfo_a06" style="color:<?=$fontcolor;?>"><?=$ShowNum;?></div>
						<div class="empinfo_a07" style="color:<?=$fontcolor;?>"><?=$objEmp["empName"];?></div>
						<div class="empinfo_a08" style="color:<?=$fontcolor;?>"><?=$objEmp["empPwd"];?></div>
						<div class="empinfo_a09" style="color:<?=$fontcolor;?>"><?=$objEmp["imNumber"];?></div>  
						<div class="empinfo_a10" style="color:<?=$fontcolor;?>"><?=$objEmp["empType"];?></div>
						<div class="empinfo_a11" style="line-height:0px;" >
							<button class="btnblue_mouseout" style="width:50px;height:25px;margin-left:3px;" onmouseover="this.className='btnblue_mouseover'" onmouseout="this.className='btnblue_mouseout'" onmousedown="this.className='btnblue_mousedown'"  onmouseup="this.className='btnblue_mouseup'" onclick="self.location='empaddnew.php?ID=<?=$objEmp["id"];?>&Type=1&pgno=<?=$PageNo;?>'" ><?="编辑";?></button>
				            <button class="btnblue_mouseout" style="width:50px;height:25px;margin-left:3px;" onmouseover="this.className='btnblue_mouseover'" onmouseout="this.className='btnblue_mouseout'" onmousedown="this.className='btnblue_mousedown'"  onmouseup="this.className='btnblue_mouseup'" onclick="DeleteEmp('<?=$objEmp["id"];?>')"><?="删除";?></button>
						</div>
			    	</div>
		      	<?
					$i_web++;
				}
				?>
				
				<!-- 显示 页码-->
				<div class="empinfo_a04" align="center">
					<?
					if($PageNo>1)
					{ 
						$npage = $PageNo-1;  /*上一页*/
					?>
						<span><a class="paging_page" href="empinfo.php?pgno=1"><b>首页</b></a></span> 
						<span><a class="paging_page" href="empinfo.php?pgno=<?=$npage;?>"><b>上一页</b></a></span>
					<?
					}
					else
					{
					?>
						<span class="paging_page"><b>首页</b></span>
						<span class="paging_page"><b>上一页</b></span>
					<?
					}
					for($i=$start;$i<=$stop;$i++)
					{
						if($i==$PageNo)
						{
					?>
						<span class="paging_page"><b><?=$i?></b></span>
					<?
					 	}
						else
						{
					?>	
						<span class="paging_page"><a href="empinfo.php?pgno=<?=$i;?>"><b><?=$i;?></b></a></span>
					<?	
						}  
					}
					
				   	if($PageNo < $total_pages)
				   	{
				   		$npage = $PageNo+1;   /*下页*/
				  	?>   
				  		<span class="paging_page"><a href="empinfo.php?pgno=<?=$npage;?>"><b>下一页</b></a></span> 
				  		<span class="paging_page"><a href="empinfo.php?pgno=<?=$total_pages;?>"><b>尾页</b></a></span>
				  	<? 
				  	}
				  	else
				  	{?>
						<span class="paging_page"><b>下一页</b></span>
						<span class="paging_page"><b>尾页</b></span>
				  	<?
				  	}
				  	?>
		    	</div>
			</div>
		</div>
	</div>
</body>

</html>
